#!/usr/bin/perl -w
use strict;

print "Content-Type: text/html\n\n";
print "<pre>You Ask\n";

use DBI;
our $h=DBI->connect('DBI:mysql:database=Down','root') || die $DBI::errstr;
our $ns=$h->prepare(qq/insert into down (url,size) values (?,?)/);
$_=$ENV{'QUERY_STRING'}||'';
my $size;

$size=$1 if s/^size=(\d+)&//;

s/^url=//;s/\+/ /g;
s/\%([0-9a-f]{2})/chr(hex($1))/ige;
s{^ubuntu/|^.*http://cdit(?:|\:\d+)/ubuntu/}{http://archive.ubuntu.com/ubuntu/};

print <<EOF;
<b>$_</b>
</pre>
<form action='/cgi-bin/add.cgi'>
<input type=text name=url length=100>
EOF

$ns->execute($_,$size) if $_;

$ns->finish();

$ns=$h->prepare(qq/select id,url,size from down where status=0 order by id desc/);
$ns->execute();
print "<table>";
while (my @a=$ns->fetchrow_array())
{
    my $id=shift @a;
    $id="<a href='cancel.cgi?$id' target='action'>$id</a>";
    print "<tr>",map("<td>$_</td>",$id,@a),"</tr>"
}
print "</table><iframe name='action' height=80 border=0></iframe>";

